/*
 * Copyright 2011 The Rusted Roof, LLC.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package org.proteusframework.core.api;


import org.proteusframework.core.api.ext.IAdapterManager;
import org.proteusframework.core.api.model.INamespace;
import org.proteusframework.core.base.NoSuchNamespaceException;

/**
 * Provides platform-agnostic access to the abstract factory used for requesting concrete
 * factory instances that are capable of producing concrete plugin instances.
 *
 * @author Tacoma Four
 */
public interface IPlatformDelegate
{
    /**
     * Access details about the Proteus runtime engine.
     *
     * @param engineClassType Engine class type. For a
     *                        {@link org.proteusframework.core.runtime.StandardProteusApplication}, this is always
     *                        <code>IRuntimeEngine.class</code>. However, if an application is configured to support the
     *                        Proteus Platform Services, then either <code>IRuntimeEngine.class</code> or
     *                        <code>IExtendedRuntimeEngine.class</code> can be used, depending on how deeply the caller
     *                        needs to reach into the runtime engine.
     * @param <T>             Specifies the type of <code>IRuntimeEngine</code> to retrieve
     * @return Runtime engine
     * @throws IllegalArgumentException when the engine cannot be accessed using the specified class
     */
    <T extends IRuntimeEngine> T getEngine(Class<T> engineClassType) throws IllegalArgumentException;

    /**
     * Convenience method for accessing a derived <code>IPlatformDelegate</code>, such as an
     * <code>IExtendedPlatformDelegate</code>, in instances where the Proteus Platform Services are installed and the
     * application is an <code>ExtendedProteusApplication</code>.
     *
     * @param delegateClassType Target delegate, such as <code>IExtendedPlatformDelegate.class</code>
     * @param <T>               Specifies the derived platform delegate to adapt to
     * @return Derived delegate
     * @throws IllegalArgumentException when this delegate cannot be safely cast to the target delegate
     */
    <T extends IPlatformDelegate> T adapt(Class<T> delegateClassType) throws IllegalArgumentException;

    /**
     * Access the primordial factory registrar, typically an instance of
     * {@link org.proteusframework.core.runtime.ProteusRegistrar}.
     * <p/>
     * This method is thread-safe.
     *
     * @return Factory registrar
     */
    IFactoryRegistrar getFactoryRegistrar();

    /**
     * Access the Proteus Factory Registrar to locate a specific Plugin Registrar.
     * <p/>
     * This method is thread-safe.
     *
     * @param namespace Qualified name of the plugin registrar to locate
     * @return Plugin Registrar
     * @throws org.proteusframework.core.base.NoSuchNamespaceException
     *          When the registrar has no record of the qualified name
     */
    IPluginRegistrar getPluginRegistrar(INamespace namespace) throws NoSuchNamespaceException;

    /**
     * Access the platform adapter manager.
     *
     * @return Adapter manager
     */
    IAdapterManager getAdapterManager();
}
